<?php
namespace app\center\controller;
use app\center\logic\DepartmentLogic;

/**
 * 部门api控制器
 * Created by PhpStorm.
 * User: tyll
 * Date: 2019/10/31
 * Time: 14:21
 */
class Department extends Base {

    public function __construct(){
        parent::__construct();
        $this->d_logic = new DepartmentLogic();
    }

    /**
     * 获取公用部门
     * @return \think\response\Json
     */
    public function ajax_get_public_department(){
        $params = input();
        $r = $this->check_user_token($params);
        if($r['code'] != 1){
            return json($r);
        }

        //检查用户规则
        $r = $this->d_logic->check_user_rule();
        if($r['code'] != 1){
            return json($r);
        }
        $u_detail = $r['data']['detail'];

        $maps = $this->d_logic->get_search_public_department_maps();
        $list = model('user')->get_column($maps,'DISTINCT department','','','','','',false);
        foreach($list as $k => $v){
            $d_list[$k]['name'] = $v;
            $d_list[$k]['checked'] = false;
        }
        $temp['name'] = '全部';
        $temp['checked'] = true;
        array_unshift($d_list,$temp);

        $data['list'] = $d_list;
        $data['user_department'] = $u_detail['department'];
        return json($this->d_logic->get_response(1,'OK',$data));
    }
}
